package com.xsir.ditan.admin.controller;

import com.xsir.ditan.admin.query.UserQuery;
import com.xsir.ditan.miniprogram.common.Result;
import com.xsir.ditan.admin.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author user
 * @date 2021/2/2
 */
@Slf4j
@Controller
@RequestMapping("user")
public class UserController extends BaseController{
    @Autowired
    private IUserService userService;
    
    @PostMapping("/list")
    @ResponseBody
    public Map<String,Object> list(UserQuery query) {
        return userService.getList(query);
    }
    
    /**
     * 获取记录详情
     *
     * @param id    记录ID
     * @param model 模型
     * @return
     */
    @Override
    public String edit(Integer id, Model model) {
        Map<String, Object> info = new HashMap<>();
        if (id != null && id > 0) {
            info = userService.info(id);
        }
        model.addAttribute("info", info);
        return super.edit(id, model);
    }
}
